// JavaScript Document
function enumAdd(){
	 $("#EnumsContent").append(
	 "<div class='patternItem'>"
	 +	"<div id='Enum_title' class='SubItemTitle'>"
	 +		"<div class='patternLeft'>Add Enum Item</div>"
	 +      "<div class='patternRight'>"
	 + 			"<a href='#' class='rangeRemove' onclick='enumDelete(this)' ><img class='buttonBcImg' width='20' src='./images/delete.png' /></a>  "
	 +			"<a href='#' class='rangeAdd' onclick='enumAdd()' ><img class='buttonBcImg' width='20' src='./images/add.png'/></a>"
	 +		"</div>"
	 +		"<div style='clear:both;'></div>"
	 +	"</div><!--  pattern_title end -->"
	 +	"<!-- ******************************************************************* --> "
	 +	"<div id='EnumItemContainer' class='SubItemSContainer' >"
	 +		"<div class='itemDiv'>"
	 +			"<span class='textSpan'>&nbsp;Enum name:</span>"
	 +			"<input class='inputText' id='enum_name' name='enum_name' value=''  />"
	 +			"<span class='notNullSpan'>(*String)</span>"
	 +		"</div>"
	 +		"<div class='itemDiv'>"
	 +			"<span class='textSpan'>&nbsp;Value:</span>"
	 +			"<input class='inputText' id='enum_value' name='enum_value' value=''  />"
	 +			"<!--<span class='notNullSpan'>(*Integer)</span> -->"
	 +		"</div>"
	 +		"<div class='itemDiv'>"
	 +			"<span class='textSpan'>&nbsp;Status:</span>"
	 +			"<select style='width:305px;   height:23px;'   class='inputSelect' id='enum_status' name='enum_status'>"
	 +				getStatus()
	 +			"</select>"
	 +		"</div>"
	 +		"<span class='textSpan'>&nbsp;Description:</span><br/>"
	 +		"<textarea class='intextArea'  id='enum_description' name='enum_description'></textarea>"
	 +		"<span class='textSpan'>&nbsp;Reference:</span><br/>"
	 +		"<textarea class='intextArea'  id='enum_reference' name='enum_reference'></textarea>"
	 +	"</div>"
     +"</div>"
	 );
	 $("input#B_enumAdd").hide();
}

function getStatus(){
	var StatusList = StatusArr.split("_"); 
	var optionsStr = "";
	for(i = 0 ; i < StatusList.length ; i++ ){
		optionsStr += "<option  value='"+StatusList[i]+"' >"+StatusList[i]+"</option>"
	}
	return optionsStr
}

function enumDelete(obj){
    $(obj).parent().parent().parent().remove();
    //兼容 IE and Firefox  sdf
    if( $("div#EnumsContent").html().trim().length == 0){$("input#B_enumAdd").show();}
}
/**
*  enum_name[val]enum_value[sta]enum_status[des]enum_description[ref]enum_reference
*  [enumItem]
*  enum_name[val]enum_value[sta]enum_status[des]enum_description[ref]enum_reference
*  [enumItem]
*  .....
*/
function getEnumStr(){
	var enum_name          = document.getElementsByName("enum_name");
	var enum_value         = document.getElementsByName("enum_value");
	var enum_status        = document.getElementsByName("enum_status");
	var enum_description   = document.getElementsByName("enum_description");
	var enum_reference     = document.getElementsByName("enum_reference");
	var enumItem_ParamStr  = "";
	$("input.inputText").css("border-color","");
	for(i = 0 ; i < enum_name.length ; i++){
		if("" == enum_name[i].value ){
			alert("name 不能为空！");
			$(enum_name[i]).css("border-color","red");
			$(enum_name[i]).focus();
			return false;
		}
		if(enum_name[i].value.indexOf(" ") >= 0 ){
			alert("name中不能包含“ ”!");
			$(enum_name[i]).css("border-color","red");
			$(enum_name[i]).focus();
			return false;
		}
		enumItem_ParamStr += enum_name[i].value;
		enumItem_ParamStr += "[val]" +  enum_value[i].value;
		enumItem_ParamStr += (("" == enum_status[i].value)?"":"[sta]"+enum_status[i].value);
		enumItem_ParamStr += (("" == enum_description[i].value)?"":"[des]"+enum_description[i].value);
		enumItem_ParamStr += (("" == enum_reference[i].value)?"":"[ref]"+enum_reference[i].value);
		
		//最后一个不需要加分隔�?
		if(i != enum_name.length -1){
			enumItem_ParamStr += "[enumItem]";
		}
	}
	document.getElementById("enums_para").value = enumItem_ParamStr;
	return true;
}


